package com.lzy.cloud.payment.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.payment.dtos.payment.PayBillDto;
import com.lzy.cloud.payment.entity.PayBill;
import com.lzy.cloud.payment.mapper.PayBillMapperExt;
import com.lzy.cloud.payment.service.PayBillService;
import com.lzy.cloud.payment.utils.CommonsUtil;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PayBillServiceImpl implements PayBillService {

    @Autowired
    PayBillMapperExt payBillMapperExt;

    @Override
    public boolean createPayBill(PayBillDto payBillDto) {
        int count = payBillMapperExt.insertSelective(DozerUtils.map(payBillDto,PayBill.class));
        return !CommonsUtil.isEmpty(count);
    }

    @Override
    public List<PayBillDto> selectList(PayBillDto payBillDto) {
        return payBillMapperExt.selectList(payBillDto);
    }

    @Override
    public PageInfo<PayBillDto> selectListByMemberId(Pager pager, Long memberId) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        return new PageInfo(payBillMapperExt.selectListByMemberId(memberId));
    }
}
